/*
 * @Description: 
 * @Author: MALossov
 * @Date: 2022-05-23 23:08:05
 * @LastEditTime: 2022-05-24 02:00:16
 * @LastEditors: MALossov
 * @Reference: 
 */
let ajaxfilelist = new XMLHttpRequest();
ajaxfilelist.onreadystatechange = function () {
    if (ajaxfilelist.readyState == 4 && ajaxfilelist.status == 200) {
        let data = JSON.parse(ajaxfilelist.responseText);
        let len = data.files.length;
        let filetable = document.getElementById("filelist");
        for (let i = 0; i < len; i++) {
            let selectorTd = document.createElement("td");
            let selector = document.createElement("input");
            selector.setAttribute("class", "radio_type");
            selector.setAttribute("type", "radio");
            selector.setAttribute("name", "filename");
            selector.setAttribute("value", data.files[i].filename);
            selectorTd.appendChild(selector);

            let selectorLable = document.createElement("label");
            selectorLable.setAttribute("for", "radio2");
            selectorTd.appendChild(selectorLable);

            let filename = document.createElement("td");
            filename.appendChild(document.createTextNode(data.files[i].filename));
            let size = document.createElement("td");
            size.appendChild(document.createTextNode(data.files[i].filesize));
            let filetime = document.createElement("td");
            filetime.appendChild(document.createTextNode(data.files[i].time));

            let row = document.createElement("tr");
            row.appendChild(selectorTd);
            row.appendChild(filename);
            row.appendChild(size);
            row.appendChild(filetime);
            filetable.appendChild(row);
        }
    }
};
ajaxfilelist.open("post", "displayfilelist", true);
ajaxfilelist.send();

function logout() {
    var domain = document.domain;
    //var path1=document.
    let useremail = $.cookie("email");
    if (useremail == undefined) {
        alert("Plz LogIN first!!Never DOITAGAIN OK?");
        window.location.href = "/MyCloudDrive/index.html";
    }
    let ajaxlogout = new XMLHttpRequest();
    ajaxlogout.onreadystatechange = function () {
        if (ajaxlogout.status == 200 && ajaxlogout.readyState == 4) {
            window.location.href = "/MyCloudDrive/index.html";
        }
    }
    ajaxlogout.open("get", "userlogout?email=" + useremail, true);
    ajaxlogout.send();
    //document.cookie = 'username=;  expires=Thu, 01 Jan 2020 00:00:01 GMT;domain=localhost;path=/MyCloudDrive'
}